package com.cheng.controller;

import com.cheng.common.utils.BaseResult;
import com.cheng.dto.device.DeviceDTO;
import com.cheng.service.DeviceService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
public class DeviceController {

    @Resource
    DeviceService deviceService;

    @GetMapping("/device/item")
    public BaseResult<DeviceDTO> findItem(@RequestParam("id") Long id) {
        log.info("==================service2=============={}=======================================", id);
        return deviceService.findDeviceById(id);
    }

    @PostMapping("/device/post/item")
    @HystrixCommand(fallbackMethod = "queryItemFallBack")
    public BaseResult<DeviceDTO> queryItem(@RequestBody DeviceDTO deviceDTO) {
        log.info("==================service2=====post========={}=======================================", deviceDTO.toString());
        return deviceService.findDeviceById(1L);
    }

    public BaseResult queryItemFallBack() {
        return BaseResult.failureResult("请求错误");
    }

}
